home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / patches / _310ptch / logpatch / logpatch.asc < prev    next >
Text File  |  1996-07-10  |  6KB  |  174 lines

  1. BUG IN NETWARE 386 V3.1 LOGIN.EXE AND EXIT COMMAND:
  2.  
  3. The version of LOGIN.EXE shipped with NetWare 3.1 (VERSION
  4. reports 3.08, 96171 bytes, 5/29/90, 1:52pm), has a bug in
  5. processing the login script "EXIT" command, which can cause
  6. system hangups with programs and device drivers that expand or
  7. modify the keyboard buffer.
  8.  
  9. Examples of programs that conflict with the new LOGIN are certain
  10. versions of IRMA's E78 program (specifically the KYBDDRV.SYS
  11. device driver) and the public domain program KBDBUFF.COM which
  12. was published in a recent Microsoft Systems Journal.
  13.  
  14. Typically, if there is a conflict, it will appear after a
  15. workstation logs into the network.  After the user presses a few
  16. keys, unpredictable results will occur as the keyboard buffer
  17. overwrites BIOS variables (overwriting the video parameters can
  18. cause some real neat effects).
  19.  
  20. TECHNICAL INFORMATION:
  21.  
  22. In the BIOS data segment at segment 40h, the BIOS allocates
  23. several variables related to the keyboard buffer.
  24.  
  25. The keyboard buffer is a 16-byte circular buffer within this
  26. segment at offset 1Eh.  Different BIOS variables define the
  27. physical start (word at offset 80h) and end (word at offset 82h)
  28. of the buffer, as well as the current logical head (word at
  29. offset 1Ah) and tail (word at offset 1Ch) within the circular
  30. buffer.
  31.  
  32. Programs that expand the keyboard buffer typically move the
  33. physical buffer to another larger location in memory.  This is
  34. done by modifying the physical start and end offsets of the
  35. buffer, and then initializing the head and tail pointers to the
  36. start of the buffer.
  37.  
  38. However, the LOGIN.EXE program's EXIT command assumes that the
  39. keyboard buffer is located at offset 1Eh within the BIOS data
  40. area.
  41.  
  42. When the EXIT command is processed, the text string that follows
  43. the EXIT command is stuffed into the buffer, and the head pointer
  44. is initialized to 1Eh, and the tail to the end of the stuffed
  45. string.  If the BIOS variables define a different physical
  46. keyboard buffer, the BIOS data area will be filled with somewhat
  47. random information from the keyboard.
  48.  
  49. WHAT THE PATCH DOES
  50.  
  51. Fortunately, LOGIN.EXE can be patched to prevent this problem.
  52.  
  53. The following excerpt is the troublesome code within LOGIN.EXE:
  54.       1.) MOV BX,40h
  55.           MOV ES,BX
  56.       2.) MOV BX,1Ch
  57.       3.) MOV AX,WORD PTR [BP-6]
  58.           SHL AX,1
  59.       4.) ADD AX,1Eh
  60.           MOV WORD PTR ES:[BX],AX
  61.       5.) MOV BX,1Ah
  62.           MOV WORD PTR ES:[BX],1Eh
  63.       6.) MOV WORD PTR [BP-0Ah],1Eh
  64.  
  65. What's this code doing?
  66.  
  67. 1.)  The ES segment register is initialized to point to the BIOS
  68.      data area at segment 40h.
  69.  
  70. 2.)  BX is initialized to be a pointer to the logical tail of the
  71.      keyboard buffer (1Ch).
  72.  
  73. 3.)  The word at BP-6 is the length of the character string being
  74.      passed to the EXIT command.  Since characters are stored as
  75.      two bytes in the keyboard buffer (ASCII code and scan code),
  76.      shifting this value to the left by one (same as multiplying
  77.      by two), produces the length of the string being stored in
  78.      the keyboard buffer.
  79.  
  80. 4.)  LOGIN.EXE assumes that the keyboard buffer begins at offset
  81.      1Eh within this segment.  (This is the BIOS default.)  To
  82.      compute the new tail of the buffer, the length of the string
  83.      being stored in the buffer is added to this assumed starting
  84.      offset.  The computed tail of the buffer is stored in the
  85.      appropriate BIOS variable.
  86.  
  87. 5.)  The logical head of the keyboard (offset 1Ah) is initialized
  88.      to 1Eh (the assumed start of the keyboard buffer).
  89.  
  90. 6.)  Some other variable used within LOGIN.EXE is also
  91.      initialized to 1Eh, the assumed start of the keyboard
  92.      buffer.
  93.  
  94. So, we must patch LOGIN.EXE to read the physical starting
  95. location of the keyboard buffer from the BIOS data area.  The
  96. offset of the start of the physical keyboard buffer is a word at
  97. offset 80h of segment 40h.
  98.  
  99. The following replacement code, which is carefully constructed to
  100. be the same size, does the trick:
  101.  
  102.       1.) MOV BX,40h
  103.           MOV ES,BX
  104.       2.) MOV BL,1Ch
  105.       3.) MOV AX,WORD PTR [BP-6]
  106.           SHL AX,1
  107.       4.) ADD AX,WORD PTR ES:[80]
  108.           MOV WORD PTR ES:[BX],AX
  109.       5.) DEC BX
  110.           DEC BX
  111.       6.) MOV AX,WORD PTR ES:[80]
  112.           MOV WORD PTR ES:[BX],AX
  113.       7.) MOV WORD PTR [BP-0Ah],AX
  114.  
  115. 1.)  No change...included for clarity.
  116.  
  117. 2.)  To conserve a byte, only the lower byte of BL is initialized
  118.      to 1Ch.  The high byte is already zero from instruction
  119.      sequence 1.
  120.  
  121. 3.)  No change.
  122.  
  123. 4.)  Rather than assuming the starting address of the keyboard
  124.      buffer, we use the physical starting offset defined by the
  125.      word at offset 80h.  To compute the new tail of the buffer,
  126.      the length of the string being stored in the buffer is added
  127.      to this assumed starting offset.  The computed tail of the
  128.      buffer is stored in the appropriate BIOS variable.
  129.  
  130. 5.)  Since BX already equals 1Ch, we can save a byte in setting
  131.      BX to 1Ah by issuing two DEC BX commands.
  132.  
  133. 6.)  We move the BIOS defined start of the physical keyboard
  134.      buffer to the AX register for easier retrieval.  The logical
  135.      head of the buffer is then initialized to this same value.
  136.  
  137. 7.)  Same as 6 above, except that we use the BIOS defined start
  138.      of the buffer rather than the assumed start.
  139.  
  140.  
  141.  
  142. OK, SO HOW DO I ACTUALLY APPLY THE PATCH
  143.  
  144. The patch is applied using the PATCH.EXE program found in other
  145. patches here on NetWire.  Hopefully Novell doesn't object to my
  146. using it here.
  147.  
  148. The patch file, LOGPATCH, simply instructs PATCH.EXE to search
  149. and replace the code as outlined above.
  150.  
  151. To apply the patch:
  152.  
  153. 1.)  Make a backup copy of LOGIN.EXE.
  154.  
  155. 2.)  Execute PATCH LOGIN.EXE LOGPATCH.
  156.  
  157. 3.)  Test it and make sure that it works for you.
  158.  
  159.  
  160.  
  161. DISCLAIMERS
  162. This is not a Novell supplied or supported patch, although I hope
  163. that Novell will take notice and correct this problem in future
  164. releases.
  165.  
  166. Also, you're trying the patch at your own risk.  I'm not aware of
  167. any potential side effects, and this document describes the patch
  168. to the best of my knowledge.
  169.  
  170.  
  171.  
  172. Brett Warthen
  173. (the original LAN Shark)
  174.